﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JWFW.SFL;
using System.IO;

namespace TestTech
{
    public partial class FrmAMFHelper : Form
    {
        public FrmAMFHelper()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int startLength = CommonOP.GetInt(this.textBox1.Text.Trim());
            int dataLength = CommonOP.GetInt(this.textBox2.Text.Trim());
            string original = this.richTextBox1.Text;
            string[] data = CommonOP.SplitString(original);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                string tmp = data[i];
                if (tmp.Length < startLength)
                {
                    continue;
                }
                tmp = tmp.Substring(startLength).Trim();
                if (tmp.Length >= dataLength * 3)
                {
                    tmp = tmp.Substring(0, dataLength * 3);
                }
                sb.AppendLine(tmp);
            }
            this.richTextBox1.Text = sb.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            byte[] data = HexOP.HexToBytes(this.richTextBox1.Text);
            File.WriteAllBytes(@"c:\test\tmp.dat", data);
        }

        private void btn_format_Click(object sender, EventArgs e)
        {
            string tmp = HexOP.RefineHex(this.richTextBox1.Text);
            StringBuilder sb = new StringBuilder(100);
            for (int i = 0; i < tmp.Length / 2; i++)
            {
                if (i != 0 && i % 16 == 0)
                {
                    sb.Append("\r\n");
                }
                string t = tmp.Substring(i * 2, 2);
                if (t == "==")
                {
                    sb.Append("==\r\n");
                    tmp = tmp.Remove(0, i * 2 + 2);
                    i = -1;
                    continue;
                }
                sb.Append(t).Append(" ");
            }
            this.richTextBox1.Text = sb.ToString();
        }
    }
}
